package com.yanqu.road.entity.activity.sonhai.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.pawnshop.PawnshopConfig;
import com.yanqu.road.entity.activity.sonhai.data.SonHaiPatronsData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eMallCategory;
import com.yanqu.road.entity.enums.eShopType;
import com.yanqu.road.utils.MapHelper;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.commons.collections.ListUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class SonHaiConfig {

    private static Logger logger = LogManager.getLogger(SonHaiConfig.class.getName());

    // 活动信息
    private ActivityInfo activityInfo;

    Map<String, ActivityConfig> activityConfigMap;

    Map<Integer, MallInfo> mallInfoMap;
    public Map<Integer, Map<Integer, MallInfo>> rmbMallInfoTypeMap = new ConcurrentHashMap<>(); //rmb礼包 k:type k:vip,v:MallInfo

    //事件配置MAP,K:事件ID
    private Map<Integer, SonHaiEventConfig> eventConfigMap;
    //事件类型配置MAP,K:事件TYPE,K:事件ID
    private Map<Integer, Map<Integer, SonHaiEventConfig>> eventTypeConfigMap;

    //区域配置MAP,K:区域ID
    private Map<Integer, SonHaiFloorConfig> floorConfigMap;

    //buff配置，k：buffID
    private Map<Integer, SonHaiBuffConfig> buffConfigMap;

    //怪配置
    private Map<Integer, SonHaiMonsterConfig> monsterConfigMap;

    //蛋配置
    private Map<Integer, SonHaiEggConfig> eggConfigMap;

    //地图配置
    private Map<Integer, SonHaiMapConfig> mapConfigMap;

    //蛋名配置
    private Map<Integer, SonHaiEggNameConfig> eggNameConfigMap;

    /*******************************************************config参数*************************************************/

    //体力包道具ID
    private int SONHAI_ENERGY_ITEM_ID;

    //体力限用道具ID
    private int SHOW_LIMITED_USE_STRENGTH_ITEM_ID;

    //限用道具使用数量上限,K:道具ID,V:数量上限
    private Map<Integer, Long> SHOW_LIMITED_USE_ITEM_NUM;

    //体力CD时间（s）
    private int SONHAI_ENERGY_CD;

    //体力CD恢复值
    private int SONHAI_ENERGY_CD_NUM;

    //体力值上限
    private int SONHAI_ENERGY_LIMIT;

    //每日开启时间(h)
    private int SONHAI_FIGHT_DAILY_OPEN_TIME;

    //每日结束时间(h)
    private int SONHAI_FIGHT_DAILY_END_TIME;

    //山海伏兽--圣兽降临--所需体力，K：圣兽降临次数，V:需要消耗的体力
    public Map<Integer, Integer> SONHAI_ENERGY_BUFF_NUM;
    private int maxBuffNumEnergy = 5;

    //山海伏兽--消耗体力恢复协助次数
    private int SONHAI_INIT_HELP_NUM;

    //山海伏兽--消耗体力恢复协助次数
    private List<Integer> SONHAI_COST_ENERGY_HELP_NUM;

    //山海伏兽--兽王--体力消耗（发现者/协助者）
    private List<Integer> SONHAI_ENERGY_SPECIAL_PVE_COST;

    //山海伏兽--体力消耗（发现者）-- 非兽王/异兽栖/营地
    private List<Integer> SONHAI_ENERGY_FINDER_COST;

    //山海伏兽--体力消耗（协助者）-- 非兽王/异兽栖/营地
    private List<Integer> SONHAI_ENERGY_HELPER_COST;

    //山海伏兽--胜场伏兽积分加成(胜场1次加成千分比|胜场2次加成千分比).K:胜场数,V:积分加成
    private Map<Integer, Integer> SONHAI_SCORE_VICTORY_ADD;

    //山海伏兽--营地--随机对手的范围（个人排名,【min|max】 举例：个人排名-50到个人排名+50之间去随机
    private List<Integer> SONHAI_PVP_PLAYER_RANGE;

    //山海伏兽--营地--被攻击次数初始值
    private int SONHAI_PVP_ATTACKED_NUM_INIT;

    //山海伏兽--营地--悬赏山海灵气,连杀人数×悬赏山海灵气
    private int SONHAI_PVP_KILL_STREAK_SCORE;

    //山海伏兽--异兽栖--共享池异兽蛋数量上限
    private int SONHAI_EGG_SHARED_NUM;

    //山海伏兽--异兽栖--整个活动异兽蛋数量上限
    private int SONHAI_EGG_NUM;

    //玩家赚钱前n门客
    private int SONHAI_POWER_PATRONS_NUM_MAX;

    //每个门客战力转换(参数1~参数3
    private List<Long> SONHAI_POWER_PARAM;

    //怪物战力转换(参数5 vip0|vip1...vip15
    private List<Integer> SONHAI_MONSTER_POWER_PARAM;

    //怪物战力转换（vip0保底值
    private long SONHAI_MONSTER_POWER_MIN;

    //怪物战力转换（vip取值，导入区服前X天内的活跃玩家，玩家要去重
    private int SONHAI_MONSTER_POWER_DAY;

    //山海伏兽--每次buff免费刷新次数上限
    private int SONHAI_BUFF_REFRESH_NUM_FREE;

    //山海伏兽--每次buff刷新元宝消耗.初始值|递增值|最大值  元宝消耗公式 = min（初始值 + max（刷新次数-1，0）×递增值，最大值）
    private List<Integer> SONHAI_BUFF_REFRESH_COST;

    //山海伏兽--日志，镇伏大于等于X级的兽群
    private int SONHAI_LOG_PVE_LEVEL;

    //协助CD
    private int SONHAI_HELP_CD;

    //山海伏兽--异兽栖--持蛋战力增加（持蛋CD/min|战力增长千分比|战力上限千分比
    private List<Integer> SONHAI_EGG_POWER_ADD = new ArrayList<>();

    //山海伏兽-重置队友同意时间（单位s）
    private int SONHAI_RESET_AGREE_TIME;

    /**
     * 现金礼包-有效期
     */
    public int SONHAI_MALL_KEEP_TIME = 3600 * 4;

    /*******************************************************config参数*************************************************/

    public SonHaiConfig(ActivityInfo activityInfo,
                        Map<String, ActivityConfig> activityConfigMap,
                        Map<Integer, MallInfo> mallInfoMap,
                        Map<Integer, SonHaiEventConfig> eventConfigMap,
                        Map<Integer, SonHaiFloorConfig> floorConfigMap,
                        Map<Integer, SonHaiBuffConfig> buffConfigMap,
                        Map<Integer, SonHaiMonsterConfig> monsterConfigMap,
                        Map<Integer, SonHaiEggConfig> eggConfigMap,
                        Map<Integer, SonHaiMapConfig> mapConfigMap,
                        Map<Integer, SonHaiEggNameConfig> eggNameConfigMap) {
        this.activityInfo = activityInfo;
        this.activityConfigMap = activityConfigMap;
        this.mallInfoMap = mallInfoMap;
        this.eventConfigMap = eventConfigMap;
        this.floorConfigMap = floorConfigMap;
        this.buffConfigMap = buffConfigMap;
        this.monsterConfigMap = monsterConfigMap;
        this.eggConfigMap = eggConfigMap;
        this.mapConfigMap = mapConfigMap;
        this.eggNameConfigMap = eggNameConfigMap;
        //解析出eventTypeConfigMap
        Map<Integer, Map<Integer, SonHaiEventConfig>> eventTypeConfigMap = new HashMap<>();
        for (SonHaiEventConfig eventConfig : eventConfigMap.values()) {
            Map<Integer, SonHaiEventConfig> itemMap = eventTypeConfigMap.computeIfAbsent(eventConfig.getEventType(), k -> new HashMap<>());
            itemMap.put(eventConfig.getId(), eventConfig);
        }
        this.eventTypeConfigMap = eventTypeConfigMap;
        //解析出现金礼包MAP
        Map<Integer, Map<Integer, MallInfo>> rmbMallInfoTypeMap = new ConcurrentHashMap<>();
        for(MallInfo item : mallInfoMap.values()) {
            if (item.getCategory() != eMallCategory.SonHaiGift.getValue()) {
                continue;
            }
            String[] str = item.getExtendParam().split("\\|");
            int type = Integer.parseInt(str[0]);
            int vip = Integer.parseInt(str[1]);
            Map<Integer, MallInfo> vipMap = rmbMallInfoTypeMap.computeIfAbsent(type, k -> new ConcurrentHashMap<>());
            vipMap.put(vip, item);
        }
        this.rmbMallInfoTypeMap = rmbMallInfoTypeMap;
        //解析config
        this.parseConfig(activityConfigMap);
    }

    /**
     * 解析config
     * @param activityConfigMap
     */
    private void parseConfig(Map<String, ActivityConfig> activityConfigMap) {
        this.SONHAI_ENERGY_ITEM_ID = activityConfigMap.get("SONHAI_ENERGY_ITEM_ID").getIntValue();
        this.SHOW_LIMITED_USE_STRENGTH_ITEM_ID = activityConfigMap.get("SHOW_LIMITED_USE_STRENGTH_ITEM_ID").getIntValue();
        String showLimitedUseItemNum = activityConfigMap.get("SHOW_LIMITED_USE_ITEM_NUM").getValue();
        String[] showLimitedUseItemNumArr = showLimitedUseItemNum.split("\\|");
        Map<Integer, Long> showLimitedUseItemNumMap = new HashMap<>();
        for (String item : showLimitedUseItemNumArr) {
            String[] itemArr = item.split("=");
            int itemId = Integer.parseInt(itemArr[0]);
            long itemNum = Long.parseLong(itemArr[1]);
            showLimitedUseItemNumMap.put(itemId, itemNum);
        }
        this.SHOW_LIMITED_USE_ITEM_NUM = showLimitedUseItemNumMap;
        this.SONHAI_ENERGY_CD = activityConfigMap.get("SONHAI_ENERGY_CD").getIntValue();
        this.SONHAI_ENERGY_CD_NUM = activityConfigMap.get("SONHAI_ENERGY_CD_NUM").getIntValue();
        this.SONHAI_ENERGY_LIMIT = activityConfigMap.get("SONHAI_ENERGY_LIMIT").getIntValue();
        this.SONHAI_FIGHT_DAILY_OPEN_TIME = activityConfigMap.get("SONHAI_FIGHT_DAILY_OPEN_TIME").getIntValue();
        this.SONHAI_FIGHT_DAILY_END_TIME = activityConfigMap.get("SONHAI_FIGHT_DAILY_END_TIME").getIntValue();

        //体力相关
        String energyBuffNum = activityConfigMap.get("SONHAI_ENERGY_BUFF_NUM").getValue();
        this.SONHAI_ENERGY_BUFF_NUM = StringUtils.parseStringToMap(energyBuffNum);
        Map.Entry<Integer, Integer> lastEntry = MapHelper.getLastEntry(this.SONHAI_ENERGY_BUFF_NUM);
        if (lastEntry != null) {
            this.maxBuffNumEnergy = lastEntry.getValue();
        }
        this.SONHAI_INIT_HELP_NUM = activityConfigMap.get("SONHAI_INIT_HELP_NUM").getIntValue();
        this.SONHAI_COST_ENERGY_HELP_NUM = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_COST_ENERGY_HELP_NUM").getValue(), "\\|");
        this.SONHAI_ENERGY_SPECIAL_PVE_COST = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_ENERGY_SPECIAL_PVE_COST").getValue(), "\\|");
        this.SONHAI_ENERGY_FINDER_COST = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_ENERGY_FINDER_COST").getValue(), "\\|");
        this.SONHAI_ENERGY_HELPER_COST = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_ENERGY_HELPER_COST").getValue(), "\\|");

        String scoreVictoryAdd = activityConfigMap.get("SONHAI_SCORE_VICTORY_ADD").getValue();
        Map<Integer, Integer> scoreVictoryAddMap = new HashMap<>();
        int i = 1;
        for (String item : scoreVictoryAdd.split("\\|")) {
            scoreVictoryAddMap.put(i, Integer.parseInt(item));
            i++;
        }
        this.SONHAI_SCORE_VICTORY_ADD = scoreVictoryAddMap;
        this.SONHAI_PVP_PLAYER_RANGE = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_PVP_PLAYER_RANGE").getValue(), "\\|");
        this.SONHAI_PVP_ATTACKED_NUM_INIT = activityConfigMap.get("SONHAI_PVP_ATTACKED_NUM_INIT").getIntValue();
        this.SONHAI_PVP_KILL_STREAK_SCORE = activityConfigMap.get("SONHAI_PVP_KILL_STREAK_SCORE").getIntValue();
        this.SONHAI_EGG_SHARED_NUM = activityConfigMap.get("SONHAI_EGG_SHARED_NUM").getIntValue();
        this.SONHAI_EGG_NUM = activityConfigMap.get("SONHAI_EGG_NUM").getIntValue();

        this.SONHAI_POWER_PATRONS_NUM_MAX = activityConfigMap.get("SONHAI_POWER_PATRONS_NUM_MAX").getIntValue();
        this.SONHAI_POWER_PARAM = StringUtils.stringToLongList(activityConfigMap.get("SONHAI_POWER_PARAM").getValue(), "\\|");
        this.SONHAI_MONSTER_POWER_PARAM = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_MONSTER_POWER_PARAM").getValue(), "\\|");
        this.SONHAI_MONSTER_POWER_MIN = activityConfigMap.get("SONHAI_MONSTER_POWER_MIN").getLongValue();
        this.SONHAI_MONSTER_POWER_DAY = activityConfigMap.get("SONHAI_MONSTER_POWER_DAY").getIntValue();

        this.SONHAI_BUFF_REFRESH_NUM_FREE = activityConfigMap.get("SONHAI_BUFF_REFRESH_NUM_FREE").getIntValue();
        this.SONHAI_BUFF_REFRESH_COST = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_BUFF_REFRESH_COST").getValue(), "\\|");

        this.SONHAI_LOG_PVE_LEVEL = activityConfigMap.get("SONHAI_LOG_PVE_LEVEL").getIntValue();
        this.SONHAI_HELP_CD = activityConfigMap.get("SONHAI_HELP_CD").getIntValue();

        if (activityConfigMap.containsKey("SONHAI_EGG_POWER_ADD")) {
            this.SONHAI_EGG_POWER_ADD = StringUtils.stringToIntegerList(activityConfigMap.get("SONHAI_EGG_POWER_ADD").getValue(), "\\|");
        }

        this.SONHAI_RESET_AGREE_TIME = activityConfigMap.get("SONHAI_RESET_AGREE_TIME").getIntValue();
    }

    public int getEnergyItemId() {
        return SONHAI_ENERGY_ITEM_ID;
    }

    public int getShowLimitedUseStrengthItemId() {
        return SHOW_LIMITED_USE_STRENGTH_ITEM_ID;
    }

    public Map<Integer, Long> getShowLimitedUseItemNumMap() {
        return SHOW_LIMITED_USE_ITEM_NUM;
    }

    public int getEnergyCd() {
        return SONHAI_ENERGY_CD;
    }

    public int getEnergyCdNum() {
        return SONHAI_ENERGY_CD_NUM;
    }

    public int getEnergyLimit() {
        return SONHAI_ENERGY_LIMIT;
    }

    public int getFightDailyOpenTime() {
        return SONHAI_FIGHT_DAILY_OPEN_TIME;
    }

    public int getFightDailyEndTime() {
        return SONHAI_FIGHT_DAILY_END_TIME;
    }

    public Map<Integer, Integer> getScoreVictoryAdd() {
        return SONHAI_SCORE_VICTORY_ADD;
    }

    public List<Integer> getPvpPlayerRange() {
        return SONHAI_PVP_PLAYER_RANGE;
    }

    public int getPvpAttackedNumInit() {
        return SONHAI_PVP_ATTACKED_NUM_INIT;
    }

    public int getPvpKillStreakScore() {
        return SONHAI_PVP_KILL_STREAK_SCORE;
    }

    public int getEggSharedNum() {
        return SONHAI_EGG_SHARED_NUM;
    }

    public int getEggNum() {
        return SONHAI_EGG_NUM;
    }

    public int getInitHelpNum() {
        return SONHAI_INIT_HELP_NUM;
    }

    public List<Integer> getCostEnergyHelpNum() {
        return SONHAI_COST_ENERGY_HELP_NUM;
    }

    public List<Integer> getEnergySpecialPveCost() {
        return SONHAI_ENERGY_SPECIAL_PVE_COST;
    }

    public List<Integer> getEnergyFinderCost() {
        return SONHAI_ENERGY_FINDER_COST;
    }

    public List<Integer> getEnergyHelperCost() {
        return SONHAI_ENERGY_HELPER_COST;
    }

    public int getPowerPatronsNumMax() {
        return SONHAI_POWER_PATRONS_NUM_MAX;
    }

    public List<Long> getPowerParam() {
        return SONHAI_POWER_PARAM;
    }

    public List<Integer> getMonsterPowerParam() {
        return SONHAI_MONSTER_POWER_PARAM;
    }

    public int getMonsterPowerParamByVipLevel(int vipLevel) {
        if (vipLevel >= SONHAI_MONSTER_POWER_PARAM.size()) {
            return SONHAI_MONSTER_POWER_PARAM.get(SONHAI_MONSTER_POWER_PARAM.size() - 1);
        }
        return SONHAI_MONSTER_POWER_PARAM.get(vipLevel);
    }

    public long getMonsterPowerMin() {
        return SONHAI_MONSTER_POWER_MIN;
    }

    public int getMonsterPowerDay() {
        return SONHAI_MONSTER_POWER_DAY;
    }

    public int getLogPveLevel() {
        return SONHAI_LOG_PVE_LEVEL;
    }

    public int getHelpCd() {
        return SONHAI_HELP_CD;
    }

    public int getResetAgreeTime() {
        return SONHAI_RESET_AGREE_TIME;
    }

    public List<Integer> getEggPowerAdd() {
        return SONHAI_EGG_POWER_ADD;
    }

    public int getMallKeepTime() {
        return SONHAI_MALL_KEEP_TIME;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public Map<Integer, MallInfo> getMallInfoMap() {
        return mallInfoMap;
    }

    public Map<Integer, SonHaiEventConfig> getEventConfigMap() {
        return eventConfigMap;
    }

    public Map<Integer, SonHaiFloorConfig> getFloorConfigMap() {
        return floorConfigMap;
    }

    public Map<Integer, SonHaiMonsterConfig> getMonsterConfigMap() {
        return monsterConfigMap;
    }

    public SonHaiMonsterConfig getMonsterConfig(int monsterId) {
        return monsterConfigMap.get(monsterId);
    }

    public Map<Integer, SonHaiEggConfig> getEggConfigMap() {
        return eggConfigMap;
    }

    public SonHaiEggConfig getEggConfig(int eggId) {
        return eggConfigMap.get(eggId);
    }

    public SonHaiEventConfig getEventConfig(int eventId) {
        return eventConfigMap.get(eventId);
    }

    public SonHaiFloorConfig getFloorConfig(int floorId) {
        return floorConfigMap.get(floorId);
    }

    public Map<Integer, Map<Integer, SonHaiEventConfig>> getEventTypeConfigMap() {
        return eventTypeConfigMap;
    }

    public Map<Integer, SonHaiEventConfig> getEventConfigMap(int eventType) {
        return eventTypeConfigMap.get(eventType);
    }

    public Map<Integer, SonHaiMapConfig> getMapConfigMap() {
        return mapConfigMap;
    }

    public SonHaiMapConfig getMapConfig(int mapId) {
        return mapConfigMap.get(mapId);
    }

    public Map<Integer, SonHaiEggNameConfig> getEggNameConfigMap() {
        return eggNameConfigMap;
    }

    /**
     * 获取默认区域ID
     * @return
     */
    public int getDefaultRegionId() {
        int regionId = 10001;
        for (SonHaiFloorConfig floorConfig : this.floorConfigMap.values()) {
            return floorConfig.getId();
        }
        return regionId;
    }

    /**
     * 获取区域出现兽王所需要的寻踪进度
     * @param regionId
     * @return
     */
    public int getRegionNeedProgress(int regionId) {
        SonHaiFloorConfig floorConfig = this.floorConfigMap.get(regionId);
        return floorConfig.getNeedSchedule();
    }

    /**
     * 获取事件的下一个等级事件
     * @param eventId
     * @return
     */
    public SonHaiEventConfig getNextLevelEvent(int eventId) {
        SonHaiEventConfig eventConfig = this.getEventConfig(eventId);
        Map<Integer, SonHaiEventConfig> typeMap = this.eventTypeConfigMap.get(eventConfig.getEventType());
        //获取下一个等级事件
        SonHaiEventConfig nextLevelEvent = null;
        int minLevel = eventConfig.getLevel();
        int nextLevel = Integer.MAX_VALUE;
        for (SonHaiEventConfig item : typeMap.values()) {
            if (item.getLevel() > minLevel && item.getLevel() < nextLevel) {
                nextLevelEvent = item;
                nextLevel = item.getLevel();
            }
        }
        return nextLevelEvent;
    }

    /**
     * 判断是否在每日战斗时间段
     * @return
     */
    public boolean checkInDailyBattleTime() {
        int hour = DateHelper.getHours();
        if(hour < SONHAI_FIGHT_DAILY_OPEN_TIME || hour >= SONHAI_FIGHT_DAILY_END_TIME){
            return false;
        }
        return true;
    }

    /**
     * 获取第一次圣兽降临需要的体力
     * @return
     */
    public int getFistBuffComeNeedEnergy() {
        return this.SONHAI_ENERGY_BUFF_NUM.getOrDefault(1, this.maxBuffNumEnergy);
    }

    /**
     * 获取圣兽降临需要的体力
     * @param buffComeNum
     * @return
     */
    public int getBuffComeNeedEnergy(int buffComeNum) {
        //获取需要的体力，找不到就用最大的体力
        return this.SONHAI_ENERGY_BUFF_NUM.getOrDefault(buffComeNum, this.maxBuffNumEnergy);
    }

    /**
     * 获取buff配置
     * @param buffId
     * @return
     */
    public SonHaiBuffConfig getBuffConfig(int buffId) {
        return this.buffConfigMap.get(buffId);
    }

    /**
     * 获取BUFF MAP
     * @return
     */
    public Map<Integer, SonHaiBuffConfig> getBuffConfigMap() {
        return buffConfigMap;
    }

    /**
     * 获取第一天蛋蛋的孵化事件
     * @return
     */
    public long getFistDayEggRewardCompleteTime() {
        long beginTime = this.activityInfo.getBeginTime() * 1000;
        int dailyEndTime = this.getFightDailyEndTime();
        return DateHelper.getDateForTimeByTime(beginTime, dailyEndTime, 0, 0);
    }

    /**
     * 获取随机的buff
     * @param regionId
     * @return
     */
    public SonHaiBuffConfig getRandomBuff(int regionId, Set<Integer> reBuffIdSet) {
        SonHaiFloorConfig floorConfig = this.getFloorConfig(regionId);
        Map<Integer, Long> buffWeightMap = new HashMap<>(floorConfig.getBuffWeightMap());
        //去除掉
        for (int reBuffId : reBuffIdSet) {
            buffWeightMap.remove(reBuffId);
        }
        //buff权重
        int buffId = RandomHelper.getRandomKeyByLongWeight(buffWeightMap);
        return this.buffConfigMap.get(buffId);
    }

    /**
     * 获取选择的buff list，根据区域ID
     * @param regionId
     * @param reBuffIdSet 排除的buffID
     * @return
     */
    public Set<Integer> getBuffSelectSet(int regionId, Set<Integer> reBuffIdSet) {
        Set<Integer> set = new HashSet<>();
        int selectNum = 3;//3个写死
        for (int i = 0; i < selectNum; i++) {
            SonHaiBuffConfig buffConfig = getRandomBuff(regionId, reBuffIdSet);
            if (buffConfig != null) {
                set.add(buffConfig.getId());
                reBuffIdSet.add(buffConfig.getId());
            }
        }
        return set;
    }

    /**
     * 随机地图ID
     * @return
     */
    public int getRandomMapId(int regionId) {
        Set<Integer> mapIdset = new HashSet<>();
        for (SonHaiMapConfig mapConfig : this.mapConfigMap.values()) {
            if (regionId == mapConfig.getFloor()) {
                mapIdset.add(mapConfig.getId());
            }
        }
        Integer mapId = RandomHelper.getRandomElement(mapIdset);
        if (mapId == null) {
            logger.error("山海伏兽-随机地图ID失败，找不到地图ID,{}", regionId);
            return 1;
        }
        return mapId;
    }

    /**
     * 转换战力
     * @param ability
     * @return
     */
    public long transformPatronsPower(long ability) {
        long param1 = this.getPowerParam().get(0);
        long param2 = this.getPowerParam().get(1);
        long param3 = this.getPowerParam().get(2);
        //计算
        double logValue1 = (double) ability / param1;
        double logValue2 = Math.log(logValue1);//底数为e的log计算
        long power = (long) (logValue2 * param2);
        return Math.max(power, param3);
    }

    /**
     * 获取礼包ID,根据extendParam
     * @param extendParam
     * @return
     */
    public int getMallIdByExtendParam(int extendParam) {
        for (MallInfo mallInfo : this.mallInfoMap.values()) {
            if (mallInfo.getShopType() == eShopType.SonHaiGift.getValue()) {
                if (Objects.equals(mallInfo.getExtendParam(), String.valueOf(extendParam))) {
                    return mallInfo.getMallId();
                }
            }
        }
        return 0;
    }

    /**
     * 获取刷新选择buff的消耗
     * @param num
     * @return
     */
    public int getResetRandomWaitBuffListCost(int num) {
        //收费的
        int initNum = this.SONHAI_BUFF_REFRESH_COST.get(0);
        int addNum = this.SONHAI_BUFF_REFRESH_COST.get(1);
        int maxNum = this.SONHAI_BUFF_REFRESH_COST.get(2);
        return Math.min(initNum + addNum * num, maxNum);
    }

    /**
     * 获取刷新选择buff的消耗
     * @return
     */
    public int getResetRandomWaitBuffListCost() {
        return this.SONHAI_BUFF_REFRESH_COST.get(0);
    }

    /**
     * 获取触发礼包ID
     * @param vipLevel
     * @return
     */
    public int randomTriggerMallId(int vipLevel) {
        Integer type = RandomHelper.getRandomElement(this.rmbMallInfoTypeMap.keySet());
        if (type == null) {
            return 0;
        }
        MallInfo targetMallInfo = null;
        int targetVipLevel = -1;
        Map<Integer, MallInfo> vipMap = this.rmbMallInfoTypeMap.get(type);
        for (Map.Entry<Integer, MallInfo> entry : vipMap.entrySet()) {
            MallInfo mallInfo = entry.getValue();
            int mallVipLevel = entry.getKey();
            if (vipLevel >= mallVipLevel && mallVipLevel > targetVipLevel) {
                targetMallInfo = mallInfo;
                targetVipLevel = mallVipLevel;
            }
        }
        if (targetMallInfo == null) {
            return 0;
        }
        return targetMallInfo.getMallId();
    }

    /**
     * 获取事件总积分
     * @param regionId
     * @param eventId
     * @return
     */
    public long getEventAllScore(int regionId, int eventId) {
        SonHaiFloorConfig floorConfig = this.floorConfigMap.get(regionId);
        if (floorConfig == null) {
            return 0;
        }
        SonHaiEventConfig eventConfig = this.eventConfigMap.get(eventId);
        if (eventConfig == null) {
            return 0;
        }
        return eventConfig.getMonsterScore() * floorConfig.getEnergy();
    }

    /**
     * 获取体力道具使用数量上限
     * @param propId
     * @return
     */
    public long getEnergyPropUseLimit(int propId) {
        return this.SHOW_LIMITED_USE_ITEM_NUM.getOrDefault(propId, 0L);
    }

    /**
     * 检查使用道具数量是否达到上限
     * @param propId
     * @param useNum
     * @return
     */
    public boolean checkEnergyPropUseLimit(int propId, long useNum) {
        long limit = this.getEnergyPropUseLimit(propId);
        if (limit <= 0) {
            return true;
        }
        if (useNum > limit) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        double a = Math.log(1) / Math.log(2);
        System.out.println(a);
    }
}
